package com.tenglong.teacher.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.AnswerInfo;
import com.tenglong.teacher.ui.adapter.viewholder.AnswerCollectViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.AnswerViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;
import com.tenglong.teacher.ui.answerq.answer.MyAnswerFragment;

import java.util.List;

public class AnswerAdapter extends RecyclerView.Adapter<BaseViewHolder<AnswerInfo>> {
    private List<AnswerInfo> infos;
    private AnswerListener listener;
    private String tag;

    public AnswerAdapter(List<AnswerInfo> infos, String tag) {
        this.infos = infos;
        this.tag = tag;
    }

    @Override
    public int getItemViewType(int position) {
        switch (tag) {
            case MyAnswerFragment.NOT_ANSWER:
            case MyAnswerFragment.ALREADY_ANSWER:
                return 0;
            default:
                return 1;
        }
    }

    @NonNull
    @Override
    public BaseViewHolder<AnswerInfo> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == 0) {
            return new AnswerViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_answer_handle_layout, parent, false), listener);
        } else {
            return new AnswerCollectViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.answer_collect_item_layout, parent, false), listener);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<AnswerInfo> holder, int position) {
        holder.setLayoutInfo(infos.get(position));
    }

    @Override
    public int getItemCount() {
        return infos.size();
    }

    public void setAnswerListener(AnswerListener listener) {
        this.listener = listener;
    }

    public interface AnswerListener {
        void onAnswerClick(int position);
    }
}
